#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

multiset < int > s[N];
int w[N], n;
vec G[N];

void merge(multiset < int > &a, multiset < int > &b) {
	if(a.size() < b.size()) swap(a, b);
	for(auto v : b) a.insert(v);
}

void dfs(int x) {
	for(auto y : G[x]) dfs(y), merge(s[x], s[y]);
	if(!s[x].size() || w[x] <= *s[x].begin()) s[x].insert(w[x]);
	else {
		auto it = s[x].upper_bound(w[x]); it--;
		s[x].erase(it); s[x].insert(w[x]);
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n) w[i] = in;
	rep(i, 2, n) G[in].eb(i);
	dfs(1); printf("%d\n", s[1].size());
	return 0;
}
